<%@page import="com.mconnect.msurvey.model.DevelopingLanguages"%>
<%@page import="com.mconnect.msurvey.model.TechnicalQuestions"%>
<%@page import="com.mconnect.msurvey.model.Category"%>
<%@page import="com.mconnect.msurvey.model.Questions"%>
<%@page import="com.mconnect.msurvey.model.Survey"%>
<%@page import="com.mconnect.msurvey.controller.SurveyManager"%>
<%@page import="com.mconnect.msurvey.model.Responder"%>
<%@page import="com.mconnect.msurvey.controller.PlanManager"%>
<%@page import="com.mconnect.msurvey.model.ResponderRecommended"%>
<%@page import="java.util.ArrayList"%>
<%@page import="java.util.List"%>
<%@page import="com.mconnect.msurvey.controller.RecommendedManager"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" type="text/css" href="resources/css/search_grid_style.css" />

 <style>
		body { font-size: 62.5%; }
		label, input { display:block; }
		input.text { margin-bottom:12px; width:95%; padding: .4em; }
		fieldset { padding:0; border:0; margin-top:25px; }
		h1 { font-size: 1.2em; margin: .6em 0; }
		div#users-contain { width: 350px; margin: 20px 0; }
		div#users-contain table { margin: 1em 0; border-collapse: collapse; width: 100%; }
		div#users-contain table td, div#users-contain table th { border: 1px solid #eee; padding: .6em 10px; text-align: left; }
	</style>
	<script type="text/javascript">
						$(function() {
							var plan =  $( "#id_plan" ).val();
							var typeOfPlan = $( "#typeOfPlan" ).val();
							var firstname = $( "#p_firstname" ).val();
							var lastname = $( "#p_lastname" ).val();
							var mail = $( "#p_mail" ).val();
							var status = $( "#p_status" ).val();
							var phone = $( "#p_phone" ).val();
							var type = $( "#p_type" ).val();
							var question1 = $( "#question1" ).val();
							var question2 = $( "#question2" ).val();
							var question3 = $( "#question3" ).val();
							var question4 = $( "#question4" ).val();
							var question5 = $( "#question5" ).val();
							var question6 = $( "#question6" ).val();
							var direction = $( "#direction" ).val();
							var experience = $( "#experience" ).val();
							var callCenter = 'NIE';
							var it = 'NIE';
							var telecomunication = 'NIE';
							var publicRelation = 'NIE';
							var sale = 'NIE';
							var java = 'NIE';
							var php = 'NIE';
							var javaScript = 'NIE';
							var bd_sql = 'NIE';
							var ce_plus = 'NIE';
							var python = 'NIE';
							var other = $( "#langOther" ).val();
							var ce_sharp = 'NIE';
							if($('#callCenter').is(':checked'))	callCenter = 'TAK';
							if($('#it').is(':checked'))it = 'TAK';
							if($('#telecommunication').is(':checked')) telecomunication = 'TAK';
							if($('#publicRelations').is(':checked')) publicRelation = 'TAK';
							if($('#sale').is(':checked')) sale = 'TAK';
							if($('#java').is(':checked')) java = 'TAK';
							if($('#php').is(':checked'))php = 'TAK';
							if($('#javaScript').is(':checked')) javaScript = 'TAK';
							if($('#bd_sql').is(':checked')) bd_sql = 'TAK';
							if($('#ce_plus').is(':checked')) ce_plus = 'TAK';
							if($('#python').is(':checked')) python = 'TAK';
							if($('#ce_sharp').is(':checked')) ce_sharp = 'TAK';
							
						$('#nextPage').click(function(){
							var startPage = parseFloat($( "#next" ).val());
							var page = startPage + 1;
								
							$.post(
								'searching/showSurveysContent.jsp',
								{
									pageNumber: page, id_plan: plan, firstname: firstname, lastname : lastname, phone : phone,
									mail : mail, status : status, type : type, 
									question1 : question1, question2: question2, question3 : question3, question4 : question4, question5: question5, question6 : question6,
									callCenter : callCenter, it : it, telecommunication : telecomunication, publicRelations : publicRelation, sale : sale,
									direction : direction, experience : experience, java : java, php : php, javaScript : javaScript, bd_sql : bd_sql, ce_plus : ce_plus, python : python, 
									other : other, ce_sharp : ce_sharp
												
								},
								function (content) {
									$('#users-contain').html(content);
									$( "#next" ).val(page);
									return false;
								}
							);
								
							});
						
						$('#previousPage').click(function(){
							var startPage = parseFloat($( "#next" ).val());
							var page = startPage - 1;
							
							if(page >= 1){
								$.post(
									'searching/showSurveysContent.jsp',
									{
										pageNumber: page, id_plan: plan, firstname: firstname, lastname : lastname, phone : phone,
										mail : mail, status : status, type : type,
										question1 : question1, question2: question2, question3 : question3, question4 : question4, question5: question5, question6 : question6,
										callCenter : callCenter, it : it, telecommunication : telecomunication, publicRelations : publicRelation, sale : sale,
										direction : direction, experience : experience, java : java, php : php, javaScript : javaScript, bd_sql : bd_sql, ce_plus : ce_plus, python : python, 
										other : other, ce_sharp : ce_sharp
									},
									function (content) {
										$('#users-contain').html(content);
										$( "#next" ).val(page);
										return false;
									}
								);
							}	
						});
						
						$('.surveyContent_dialogLink').click(function(){
							var _id_survey = $(this).prev('input').val();
							var _id_responder = $(this).prev('input').prev('input').val();
							var _firstname = $(this).prev('input').prev('input').prev('input').val();
							var _lastname = $(this).prev('input').prev('input').prev('input').prev('input').val();
							var _phone = $(this).prev('input').prev('input').prev('input').prev('input').prev('input').val();
							var _mail = $(this).prev('input').prev('input').prev('input').prev('input').prev('input').prev('input').val();
							var _region = $(this).prev('input').prev('input').prev('input').prev('input').prev('input').prev('input').prev('input').val();
							var _date = $(this).prev('input').prev('input').prev('input').prev('input').prev('input').prev('input').prev('input').prev('input').val();
								$.post(
										'searching/showSurveyDetails.jsp',
										{id_survey : _id_survey, id_responder: _id_responder, firstname : _firstname, lastname: _lastname, phone: _phone, mail: _mail, id_plan : plan, date : _date, region : _region },
										function (data){
											$('body').append(data);
										}
									);
							
							return false;
						});
						
						
					});
				</script>	
</head>
<body>
	
	<%
			String pageN = request.getParameter("pageNumber");
				int pageNumber = 1;
				if(pageN !=  null){
			pageNumber = Integer.parseInt(pageN);
				}
				SurveyManager sM = new SurveyManager();
				PlanManager pM = new PlanManager();
				int id_plan = Integer.parseInt(request.getParameter("id_plan"));
				String firstname = request.getParameter("firstname");
				String lastname = request.getParameter("lastname");
				String phone = request.getParameter("phone");
				String mail = request.getParameter("mail");
				String status = request.getParameter("status");
				String type = request.getParameter("type");
				String region = request.getParameter("region");
				List<Survey> surveyList = new ArrayList<Survey>();
				Questions question = new Questions(request.getParameter("question1"), request.getParameter("question2"), request.getParameter("question3"), request.getParameter("question4"), request.getParameter("question5"), request.getParameter("question6"));
				Category category = new Category(request.getParameter("callCenter"), request.getParameter("it"), request.getParameter("telecommunication"), request.getParameter("publicRelations"), request.getParameter("sale"));
				TechnicalQuestions technical = new TechnicalQuestions(request.getParameter("direction"), request.getParameter("experience")); 
				DevelopingLanguages language = new DevelopingLanguages(request.getParameter("java"), request.getParameter("php"), request.getParameter("javaScript"), request.getParameter("bd_sql"), request.getParameter("ce_plus"), request.getParameter("python"), request.getParameter("other"), request.getParameter("ce_sharp")); 
				surveyList = sM.getSurveyFromDB(question, category, id_plan, pageNumber, firstname, lastname, phone, mail, status, type, region, technical, language);
				
				if(surveyList.isEmpty() && pageN == null){
		%>
		
		<div class="ui-widget" style="width: 850px; margin-top: 20px;">
			<div class="ui-state-error ui-corner-all" style="padding: 0 .7em;">
				<p><span class="ui-icon ui-icon-alert" style="float: left; margin-right: .3em;"></span>
				<strong>Nie znaleziono wyników spełniających twoje kryteria.</strong> <br /> <br> Zmień kryteria wyszukiwania.</p>
			</div>
		</div>
		<%}else{ %>
		<div class="clear"></div>
		<input type="hidden" id="id_plan" value="<%=id_plan %>">
		<input type="hidden" id="p_firstname" value="<%=firstname %>">
		<input type="hidden" id="p_lastname" value="<%=lastname %>">
		<input type="hidden" id="p_phone" value="<%=phone %>">
		<input type="hidden" id="p_mail" value="<%=mail %>">
		<input type="hidden" id="p_status" value="<%=status %>">
		<input type="hidden" id="p_type" value="<%=type %>">
		<input type="hidden" id="question1" value="<%=question.getQuestion1() %>">
		<input type="hidden" id="question2" value="<%=question.getQuestion2() %>">
		<input type="hidden" id="question3" value="<%=question.getQuestion3() %>">
		<input type="hidden" id="question4" value="<%=question.getQuestion4() %>">
		<input type="hidden" id="question5" value="<%=question.getQuestion5() %>">
		<input type="hidden" id="question6" value="<%=question.getQuestion6() %>">
		<input type="hidden" id="callCenter" value="<%=category.getCallCenter() %>">
		<input type="hidden" id="it" value="<%=category.getIt() %>">
		<input type="hidden" id="publicReleations" value="<%=category.getPublicRelations() %>">
		<input type="hidden" id="sale" value="<%=category.getSale() %>">
		<input type="hidden" id="telecommunication" value="<%=category.getTelecommunication() %>">
		<input type="hidden" id="direction" value="<%=technical.getDirection() %>">
		<input type="hidden" id="experience" value="<%=technical.getExperience() %>">
		<input type="hidden" id="java" value="<%=language.getJava() %>">
		<input type="hidden" id="php" value="<%=language.getPhp() %>">
		<input type="hidden" id="javaScript" value="<%=language.getJavaScript() %>">
		<input type="hidden" id="ce_plus" value="<%=language.getCe_plus() %>">
		<input type="hidden" id="ce_sharp" value="<%=language.getCe_sharp() %>">
		<input type="hidden" id="python" value="<%=language.getPython() %>">
		<input type="hidden" id="other" value="<%=language.getOther() %>">
		<input type="hidden" id="bd_sql" value="<%=language.getBd_sql() %>">

		<div id="users-contain" class="ui-widget" style="width: 850px; ">
			<table id="users" class="ui-widget ui-widget-content" >
				<thead>
				<tr class="ui-widget-header ">
					<th>Imie</th>
					<th>Nazwisko</th>
					<th>Telefon</th>
					<th>Szczegóły</th>
				</tr>
				<tbody>
					<% for(Survey survey : surveyList){ %>
						<tr>
							<td> <%= survey.getId_responder().getFirstname() %></td>
							<td><%=survey.getId_responder().getLastname() %></td>
							<td><%=survey.getId_responder().getPhone() %></td>
							<td>
								<input type="hidden" value="<%=survey.getDate_survey() %>" /><input type="hidden" value="<%=survey.getRegion() %>" />
								<input type="hidden" value="<%=survey.getId_responder().getMail() %>" /><input type="hidden" value="<%=survey.getId_responder().getPhone() %>" />
								<input type="hidden" value="<%=survey.getId_responder().getLastname() %>" /><input type="hidden" value="<%=survey.getId_responder().getFirstname() %>" />
								<input type="hidden" value="<%=survey.getId_responder().getId_responder() %>" /><input type="hidden" value="<%=survey.getId_survey() %>" />
								<a class="surveyContent_dialogLink" href="#">szczegóły</a>
							</td>
						</tr>
					<%} %>	
					<tr>
						<td colspan="4" id="form">
							<div>
									<div style="float: left; margin-top: 3px;"><a href="#" id="previousPage" style="display: block;"><img alt="Previous" src="resources/images/previous.png"> </a></div>
									<div style="float: left; margin-left: 5px;"><input type="text" id="next" style="width: 20px;"  value="1" ></div>
									<div style="float: left; margin-left: 5px; margin-top: 3px;"><a href="#" id="nextPage" style="display: block;"><img alt="Next" src="resources/images/next.png"> </a> </div>
							</div>
						 </td>
					</tr>
				</tbody>	
			</table>
		</div>
	<div class="clear"></div>
		<%} %>


</body>
</html>